﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Demo.Classroom
{
    public partial class DemoBindingSource : Form
    {
        public DemoBindingSource()
        {
            InitializeComponent();

            // Thêm dữ liệu cho binding source
            bindingSource1.Add(new HocVien("Mr A", 1));
            bindingSource1.Add(new HocVien("Mr B", 2));
            bindingSource1.Add(new HocVien("Mr C", 3));
            bindingSource1.Add(new HocVien("Mr D", 4));

            comboBox1.DisplayMember = "Name";
            comboBox1.DataSource = bindingSource1;

            dataGridView1.DataSource = bindingSource1;
            bindingSource1.Position = 2;

            label2.DataBindings.Add("Text", bindingSource1, "Name");
            textBox1.DataBindings.Add("Text", bindingSource1, "Score");
        }

        void bindingSource1_ListChanged(object sender, ListChangedEventArgs e)
        {
            throw new NotImplementedException();
        }

        private void showButton_Click(object sender, EventArgs e)
        {
            label1.Text = ((HocVien)bindingSource1[0]).Name + " - " + ((HocVien)bindingSource1[0]).Score;
        }

        private void changeButton_Click(object sender, EventArgs e)
        {
            ((HocVien)bindingSource1[bindingSource1.Count - 1]).Name += " Updated";
        }

        private void addButton_Click(object sender, EventArgs e)
        {
            bindingSource1.Add(new HocVien("Mr Last", 0));
        }
    }
}
